package com.wnxy.sddfp.system.controller;

import com.wnxy.sddfp.common.model.dto.bank.CardBindDTO;
import com.wnxy.sddfp.common.model.dto.bank.SignatureDTO;
import com.wnxy.sddfp.common.model.dto.user.LoginDto;
import com.wnxy.sddfp.common.model.dto.user.UserRegistDto;
import com.wnxy.sddfp.common.model.vo.user.LoginVo;
import com.wnxy.sddfp.common.model.vo.user.UserInfoVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.system.service.IUserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户模块
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 用户注册接口开发
     * 1、请求路径：/regist
     * 2、请求方式：post
     * 3、请求参数：
     *      {
     *          "userName": "贾霞",
     *          "phone": "19827737188",
     *          "pwd": "laborum"
     *      }
     * 4、返回数据：{"code":200,"message":"success"}
     */
    @PostMapping("/regist")
    public Result regist(@RequestBody @Validated UserRegistDto userRegistDto){
        log.debug("用户注册接口,请求参数：{}",userRegistDto);
        userService.regist(userRegistDto);
        return Result.ok();
    }

    /**
     * 登录接口开发
     */
    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }

    /**
     * 用户绑卡请求
     */
    @ApiOperation("用户绑卡")
    @PostMapping("/bank/card/add")
    public Result<SignatureDTO> addBankAccount(@RequestBody CardBindDTO cardBindDTO) {
        SignatureDTO signatureDTO = userService.createConsumer(cardBindDTO);
        return Result.ok(signatureDTO);
    }

    /**
     * 根据用户id查询
     */
    @ApiOperation("根据用户id查询")
    @GetMapping("/inner/findById/{userId}")
    public Result<UserInfoVo> findById(@PathVariable("userId") Long userId) {
        UserInfoVo userInfoVo = userService.findById(userId);
        return Result.ok(userInfoVo);
    }
}















